package com.sniff.atp.controller;

import com.alibaba.fastjson2.JSONObject;
import com.sniff.atp.dto.request.CreateProductDTO;
import com.sniff.atp.entity.ToolsInfo;
import com.sniff.atp.manager.ToolsInfoMananager;
import com.sniff.atp.response.SniffResponse;
import com.sniff.atp.service.goods.GoodsService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @BelongsProject: sniff-atp
 * @BelongsPackage: com.sniff.atp.controller.goods
 * @Author: zwg
 * @CreateTime: 2023-11-17 11:40
 * @Description: client: 获取商品
 * @Version: 1.0
 */
@Api(value = "商品模块", tags = "商品模块")
@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private ToolsInfoMananager toolsInfoMananager;

    @ApiOperation("一键创建商品")
    @PostMapping("/createProduct")
    public SniffResponse<JSONObject> createProduct(@RequestBody CreateProductDTO createProductDTO) {
        ToolsInfo toolsInfo = toolsInfoMananager.selectOne(34L);
        toolsInfo.setCount(toolsInfo.getCount() + 1);
        toolsInfoMananager.updateOne(toolsInfo);

        Integer productType=createProductDTO.getProductType();
        JSONObject productInfo = new JSONObject();

        // 判断如果是线下商品，创建线下商品
        if (productType == 1) {
            productInfo = goodsService.addOfflineProduct(createProductDTO);
        }
        // 判断如果是OEM商品，创建OEM商品
        if (productType == 2) {
            productInfo = goodsService.addOEMProduct(createProductDTO);
        }
        // 判断如果是组合商品，创建组合商品
//        if (productType == 3) {
//            productInfo = goodsService.addCombinationProduct(createProductDTO);
//        }
        return SniffResponse.pass(productInfo);
    }

    @ApiOperation("一键创建商品-预发布")
    @PostMapping("/createProductPre")
    public SniffResponse<JSONObject> createProductPre(@RequestBody CreateProductDTO createProductDTO) {
        ToolsInfo toolsInfo = toolsInfoMananager.selectOne(34L);
        toolsInfo.setCount(toolsInfo.getCount() + 1);
        toolsInfoMananager.updateOne(toolsInfo);

        Integer productType=createProductDTO.getProductType();
        JSONObject productInfo = new JSONObject();

        // 判断如果是线下商品，创建线下商品
        if (productType == 1) {
            productInfo = goodsService.addOfflineProduct(createProductDTO);
        }
        // 判断如果是OEM商品，创建OEM商品
        if (productType == 2) {
            productInfo = goodsService.addOEMProductPre(createProductDTO);
        }
        // 判断如果是组合商品，创建组合商品
//        if (productType == 3) {
//            productInfo = goodsService.addCombinationProduct(createProductDTO);
//        }
        return SniffResponse.pass(productInfo);
    }
}
